<%= form_for(Settings::RateLimit.new,
             url: admin_settings_rate_limits_path,
             html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
  <details class="crayons-card">
    <summary class="crayons-subtitle-2 p-6">Rate limits and anti-spam</summary>
    <div class="p-6 pt-0">
      <fieldset class="grid gap-4">
        <div class="crayons-field">
          <%= admin_config_label :user_considered_new_days, model: Settings::RateLimit %>
          <%= admin_config_description Constants::Settings::RateLimit.details[:user_considered_new_days][:description] %>
          <%= f.number_field :user_considered_new_days,
                             class: "crayons-textfield",
                             value: Settings::RateLimit.user_considered_new_days,
                             placeholder: Constants::Settings::RateLimit.details[:user_considered_new_days][:placeholder] %>
        </div>

        <% configurable_rate_limits.each do |key, field_hash| %>
          <% next unless field_hash[:enabled] %>
          <div class="crayons-field">
            <%= admin_config_label field_hash[:title], model: Settings::RateLimit %>
            <p class="crayons-field__description">
            <%= field_hash[:description] %>
            </p>
            <%= f.number_field key,
                               class: "crayons-textfield",
                               value: Settings::RateLimit.public_send(key),
                               min: field_hash[:min],
                               placeholder: field_hash[:placeholder] %>
          </div>
        <% end %>

        <div class="crayons-field">
          <%= admin_config_label :spam_trigger_terms, model: Settings::RateLimit %>
          <%= admin_config_description Constants::Settings::RateLimit.details[:spam_trigger_terms][:description] %>
          <%= f.text_area :spam_trigger_terms,
                          class: "crayons-textfield",
                          value: Settings::RateLimit.spam_trigger_terms.join(","),
                          placeholder: Constants::Settings::RateLimit.details[:spam_trigger_terms][:placeholder] %>
        </div>
        <div class="crayons-field">
          <% # internal_content_description_spec %>
          <%= admin_config_label :internal_content_description_spec, model: Settings::RateLimit %>
          <%= admin_config_description Constants::Settings::RateLimit.details[:internal_content_description_spec][:description] %>
          <%= f.text_area :internal_content_description_spec,
                          class: "crayons-textfield",
                          value: Settings::RateLimit.internal_content_description_spec,
                          placeholder: Constants::Settings::RateLimit.details[:internal_content_description_spec][:placeholder] %>
        </div>
      </fieldset>
      <%= render "update_setting_button", f: f %>
    </div>
  </details>
<% end %>
